//
//  WebHelpViewController.m
//  PhotoStudio
//
//  Created by 华谕 on 2017/11/7.
//  Copyright © 2017年 HUYU. All rights reserved.
//

#import "WebHelpViewController.h"

@interface WebHelpViewController ()<UIWebViewDelegate>
{
    UIWebView *webView;
}
@end

@implementation WebHelpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _titleStr;
    self.navigationController.navigationBar.translucent = NO;
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT)];
    webView.delegate = self;
    [self.view addSubview:webView];
    [self requestagreement];
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *js= @"var script = document.createElement('script');"
    "script.type = 'text/javascript';"
    "script.text = \"function ResizeImages() { "
    "var myimg,oldwidth;"
    "var maxwidth = %f;"
    "for(i=0;i <document.images.length;i++){"
    "myimg = document.images[i];"
    "if(myimg.width > maxwidth){"
    "oldwidth = myimg.width;"
    "myimg.width = %f;"
    "}"
    "}"
    "}\";"
    "document.getElementsByTagName('head')[0].appendChild(script);";
    js=[NSString stringWithFormat:js,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.width-15];
    [webView stringByEvaluatingJavaScriptFromString:js];
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
}
- (void)requestagreement
{
    WEAKSELF;
    NSDictionary *dic = @{@"type":[NSString stringWithFormat:@"%ld",_typeID]};
    [HYBaseHandler requestagreementParmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            NSArray *array = obj[@"data"];
            if (array.count > 0)
            {
                NSDictionary *dictionary = array[0];
                NSString *html = dictionary[@"text"];
                dispatch_async(dispatch_get_main_queue(), ^{
                    [webView loadHTMLString:html baseURL:nil];
                });
            }
            
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
        
    }];
}

- (void)requestFindByKey
{
    WEAKSELF;
    NSString *values = @"software_desc";
    if (_typeID == 3)
    {
        values = @"privacy_policy";
    }
    NSDictionary *dic = @{@"key":values};
//    [HYBaseHandler requestFindByKeyParmers:dic Success:^(id obj) {
//        if ([obj server_Getcodecheck])
//        {
//            NSDictionary *dataDic = obj[@"data"];
//            NSString *html = dataDic[@"propertyValue"];
//            [webView loadHTMLString:html baseURL:nil];
//
//        }
//        else
//        {
//            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
//        }
//    } failed:^(NSError *error) {
//
//    }];
}

- (void)requestGuide
{
    WEAKSELF;
//    [HYBaseHandler requestGuideParmers:nil Success:^(id obj) {
//        if ([obj server_Getcodecheck])
//        {
//            NSArray *array = obj[@"data"];
//            if (array.count > 0)
//            {
//                NSDictionary *dic = array[0];
//                NSString *html = dic[@"content"];
//                [webView loadHTMLString:html baseURL:nil];
//            }
//
//
//        }
//        else
//        {
//            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
//        }
//    } failed:^(NSError *error) {
//
//    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
